/*
 * Log.cpp
 *
 *  Created on: Nov 15, 2014
 *      Author: toti
 */


#include <Misc/Log.hpp>

Log *Log::logInstance = 0;

Log::Log(){

}

Log &Log::instance(){
	if(logInstance == 0){
		logInstance = new Log();
	}
	return *Log::logInstance;
}


void Log::open(const char* logFile){

	logOutputFileStream.open(logFile, std::ofstream::out | std::ofstream::app);

	(*this)<< "***********************";
	flush();
	(*this)<< "*  ibrc-client: Log   *";
	flush();
	(*this)<< "***********************";
	flush();
}

void Log::open(std::string &logFile){
	open(logFile.c_str());
}


void Log::flush(){


	if(logOutputFileStream.is_open()){

		time_t currentTime;
		struct tm *currentTm;

		time(&currentTime);

		currentTm = gmtime(&currentTime);

		logOutputFileStream	<< currentTm->tm_hour
					<< ":" << currentTm->tm_min
					<< ":" << currentTm->tm_sec
					<< " ibrc_server > "
					<< str()
					<< "\n";

		logOutputFileStream.flush();

		str("");

	}


}

